import os

import jinja2

from glog import AppEnv

from tags import tags

__all__ = ['tpltenv']

class TemplateEnvironment(jinja2.Environment):
    """Override join_path() to enable relative template paths."""
    def join_path(self, template, parent):
        return os.path.dirname(parent) + '/' + template
        


tpltenv = TemplateEnvironment(
    loader=jinja2.FileSystemLoader(os.path.join(AppEnv.app_root, 'template'))
)

"""Load custom template filters"""
for tag in tags:
    tpltenv.filters[tag.func_name] = tag